<template>
  <div class="info_config_page">
    <div class="common_form_search">
      <el-form
        ref="searchForm"
        :inline="true"
        :model="searchForm"
        class="form-inline"
      >
        <el-form-item label="订单号">
          <el-input
            v-model="searchForm.orderNo"
            placeholder="请输入订单号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="保单号">
          <el-input
            v-model="searchForm.policyNo"
            placeholder="请输入保单号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="上保状态">
          <el-select v-model="searchForm.status" clearable placeholder="请选择">
            <el-option :value="0" label="未上保"></el-option>
            <el-option :value="1" label="已上保"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button size="small" @click="search()" type="primary"
            >查询</el-button
          >
          <el-button size="small" @click="reset()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-divider></el-divider>

    <div class="flex align-center table-top-btns">
      <h5 class="flex align-center">
        <svg-icon
          style="margin-right: 15px"
          icon-class="list"
          :size="15"
        />数据列表
      </h5>
    </div>
    <el-table :data="tableData" border>
      <el-table-column
        align="center"
        header-align="center"
        fixed
        prop="id"
        label="ID"
        width="200"
      />
      <el-table-column
        align="center"
        header-align="center"
        fixed
        prop="order_no"
        label="订单ID"
        width="220"
      />

      <el-table-column
        align="center"
        header-align="center"
        fixed
        prop="policy_no"
        label="保单号"
        width="220"
      />
      <el-table-column
        align="center"
        header-align="center"
        fixed
        label="保费"
        width="220"
      >
        <template slot-scope="scope">
          <div style="line-height: 35px">
            {{ scope.row.policy_price ? "￥" + scope.row.policy_price : "" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        header-align="center"
        label="账户余额"
        width="220"
      >
        <template slot-scope="scope">
          <div style="line-height: 35px">
            {{
              scope.row.account_balance ? "￥" + scope.row.account_balance : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        header-align="center"
        prop="create_time"
        label="保单创建时间"
        width="220"
      />
      <!-- <el-table-column
        align="center"
        header-align="center"
        label="保单官网查询地址"
        width="210"
      >
      <template slot-scope="scope">
          <span>
              <el-image style="width:100px;height:100px" :src="$globalObj.imgBaseUrl+scope.row.policy_url">
                <div
              slot="error"
              class="image-slot"
            >
              <i class="el-icon-picture-outline"></i>
            </div>
              </el-image>
          </span>
          
      </template>

      </el-table-column> -->
      <el-table-column
        align="center"
        header-align="center"
        prop="start_time"
        label="保单起保时间"
        width="220"
      />
      <el-table-column
        align="center"
        header-align="center"
        prop="end_time"
        label="保单终保时间"
        width="220"
      />

      <el-table-column
        align="center"
        header-align="center"
        prop="status"
        label="上保状态"
        width="220"
      >
        <template slot-scope="scope">
          <el-tag
            class="pointer"
            :type="scope.row.status === 0 ? 'danger' : 'success'"
            @click="getParams(scope.row.buy_result)"
            disable-transitions
          >
            {{ scope.row.status == 0 ? "失败" : "成功" }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        header-align="center"
        label="操作"
        width="275"
      >
        <template slot-scope="scope">
          <div class="operate_col">
            <el-button
              @click="checkContract(scope.row.policy_path)"
              type="primary"
              size="small"
            >
              查看保单
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <custom-page
      ref="customPage"
      :total="total"
      @getList="getList"
    ></custom-page>
    <param-dialog
      :dialogVisible="dialogVisible"
      :dialogType="dialogType"
      :responseInfo="responseInfo"
      :requestInfo="requestInfo"
      @close="closeDialog"
    ></param-dialog>
  </div>
</template>

<script>
import { getInsuranceList } from "@/api/lease";
import customPage from "@/components/customPage";
import myDatePicker from "@/components/myDatePicker";
import paramDialog from "./child/paramDialog.vue";
export default {
  components: { customPage, myDatePicker, paramDialog },
  data() {
    return {
      tableData: [],
      total: 0,
      searchForm: {
        orderNo: "",
        status: "",
        policyNo: "",
      },
      dialogVisible: false,
      dialogType: 1,
      responseInfo: {},
      requestInfo: {},
    };
  },
  methods: {
    search() {
      this.$refs.customPage.page = 1;
      this.getList();
    },
    // 重置
    reset() {
      this.searchForm = Object.assign({});
      this.getList();
    },
    checkContract(pactUrl) {
      if (!pactUrl) {
        this.$message.warning("暂无合同");
      } else {
        window.open(this.$globalObj.imgBaseUrl + pactUrl);
      }
    },
    getParams(row) {
      this.dialogType = 2;
      this.dialogVisible = true;
      this.responseInfo = row ? row : {};
      this.requestInfo = {};
    },
    closeDialog() {
      this.dialogVisible = false;
    },
    // 获取列表
    getList() {
      const { page, pageSize } = this.$refs.customPage;
      getInsuranceList({
        page,
        pageSize,
        ...this.searchForm,
      }).then((res) => {
        this.tableData = res.data;
        this.total = res.total;
      });
    },
  },
  mounted() {
    this.getList();
  },
};
</script>

<style lang="scss" scoped>
</style>
